package services

import (
	"github.com/gin-gonic/gin"
	"hitme/go-api/logic/form"
)

type wechatService struct {}

var WechatService wechatService

// Profile 获取用户详情
func (u *wechatService) Login (c *gin.Context, req form.WechatLoginReqForm) (*form.WechatLoginRespForm, error) {
	return nil, nil
	//// 调用微信接口
	//res, err := api.WechatApi.WechatLogin(req.Code)
	//if err != nil || res.Openid == "" {
	//	return nil, errors.New("请求微信接口失败,appid或私钥不匹配！")
	//}
	//
	//// 查找用户基本信息
	//userinfo := repository.UserRep.FindByOpenid(res.Openid)
	//userinfo.OpenId = res.Openid
	//userinfo.Nickname = req.Userinfo.Nickname
	//userinfo.Avatar = req.Userinfo.Avatar
	//userinfo.Gender = req.Userinfo.Gender
	//userinfo.Province = req.Userinfo.Province
	//userinfo.City = req.Userinfo.City
	//
	//// 更新用户信息
	//if userinfo.Id == 0 {
	//	userinfo, err = repository.UserRep.Create(userinfo)
	//} else {
	//	repository.UserRep.Update(userinfo.Id, userinfo)
	//}
	//
	//// 生成token
	//expiresTime := time.Now().Unix() + global.Settings.JwtInfo.ExpiredIn
	//claims := jwt.StandardClaims{
	//	Audience:  userinfo.Nickname,              // 受众
	//	ExpiresAt: expiresTime,                    // 失效时间
	//	Id:        strconv.Itoa(int(userinfo.Id)), // 编号
	//	IssuedAt:  time.Now().Unix(),              // 签发时间
	//	Issuer:    "gin hello",                    // 签发人
	//	NotBefore: time.Now().Unix(),              // 生效时间
	//	Subject:   "login",                        // 主题
	//}
	//var jwtSecret = []byte(global.Settings.JwtInfo.SignKey)
	//tokenClaims := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
	//if token, err := tokenClaims.SignedString(jwtSecret); err == nil {
	//	var authorize form.Authorize
	//	authorize.Type = "Bearer"
	//	authorize.AccessToken = token
	//	authorize.ExpiresIn = global.Settings.JwtInfo.ExpiredIn
	//
	//	return &form.WechatLoginRespForm{
	//		Authorize: authorize,
	//		UserInfo: userinfo,
	//	}, nil
	//} else {
	//	return nil, errors.New("登录失败！")
	//}
}